package com.lonely.common.threadlocals;

import com.lonely.common.core.domain.auth.LoginUser;

/**
 * @author: 黄志标
 * @date: 2025/6/20 15:28
 * @description: 登录用户线程变量
 */
public class LoginUserThreadLocal {


    /**
     * 登录用户threadlocal
     */
    public static final ThreadLocal<LoginUser> LOGIN_USER_THREAD_LOCAL = ThreadLocal.withInitial(() -> null);

    /**
     * 设置登录用户
     *
     * @param loginUser
     */
    public static void setLoginUser(LoginUser loginUser) {
        LOGIN_USER_THREAD_LOCAL.set(loginUser);
    }

    /**
     * 获取登录用户
     *
     * @return
     */
    public static LoginUser getLoginUser() {
        return LOGIN_USER_THREAD_LOCAL.get();
    }

    /**
     * 移除登录用户
     */
    public static void remove() {
        LOGIN_USER_THREAD_LOCAL.remove();
    }
}
